//
//  String + size.swift
//  Edaixi-iOS
//
//  Created by 刘树华 on 2017/11/28.
//  Copyright © 2017年 刘树华. All rights reserved.
//

import Foundation
import UIKit
extension String{
    /// 计算字符串size(实例方法)
    ///
    /// - Parameters:
    ///   - size: 字符区域
    ///   - fontSize: 字体大小
    /// - Returns: 字符串所占矩形size
    func gainStringSize(size:CGSize , fontSize:CGFloat) -> CGSize {
        let ocStr = self as NSString
        
        return ocStr.boundingRect(with: size,
                                  options: .usesLineFragmentOrigin,
                                  attributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: fontSize)],
                                  context: nil).size
        
    }
    
    /// 计算字符串size(类方法)
    ///
    /// - Parameters:
    ///   - str: 要转换的字符串
    ///   - size: 字符区域
    ///   - fontSize: 字体大小
    /// - Returns: 字符串所占矩形size
    static func gainStringSize(str:String, size:CGSize , fontSize:CGFloat) -> CGSize {
        let ocStr = str as NSString
        
        return ocStr.boundingRect(with: size,
                                  options: .usesLineFragmentOrigin,
                                  attributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: fontSize)],
                                  context: nil).size
        
    }
    
}
